package com.cat.math;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/reverse-integer/?envType=problem-list-v2&envId=math
 * @create 2025/9/22 09:26
 * @since JDK17
 */

public class Solution01 {
    public int reverse(int x) {
        int ans = 0, last = x;
        while (x != 0) {
            ans = ans * 10 + x % 10;
            x /= 10;
        }
        char[] array = String.valueOf(Math.abs(last)).toCharArray();
        char[] chars = String.valueOf(Math.abs(ans)).toCharArray();

        for (int i = 0, j = chars.length - 1; i < array.length && j >= 0; i++, j--) {
            if (array[i] != chars[j]) {
                return 0;
            }
        }
        return ans;
    }
}
